package com.fanco.learn_datastruct_leetcode.juc;/**
 * @author qiaowang 2021/8/11
 */

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author fanco
 * @Desc 描述
 */
public class ListNotSafeDemo {

    public static void main(String[] args) {
        CopyOnWriteArrayList<String> copyOnWriteArrayList = new CopyOnWriteArrayList<String>();

        List<String> list = new ArrayList<>();
        for (int i = 0; i <100; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " 线程启动");
                copyOnWriteArrayList.add(UUID.randomUUID().toString().substring(0,8));
                System.out.println(copyOnWriteArrayList);
            }, "线程" + i).start();
        }
    }
}
